﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace RuleCode.Common
{
    public class Regular
    {
        #region 判读是否是IP地址
        /// <summary>
        /// 匹配IP地址的正则表达式
        /// </summary>
        public static string IPPattern = @"^(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)$";
        /// <summary>
        /// 判断字符串是否是IP地址
        /// </summary>
        /// <param name="ipAdd">将要判断的IP地址字符串</param>
        /// <returns>True 是；False 否</returns>
        public static bool IsIPAddress(string ipAdd)
        {
            return Regex.IsMatch(ipAdd, IPPattern);
        }
        #endregion

        #region 判断是否是Email地址
        /// <summary>
        /// 匹配Email地址的正则表达式
        /// </summary>
        public static string EmailPattern = @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$";
        /// <summary>
        /// 判断字符串是否是Email地址
        /// </summary>
        /// <param name="emailAdd"></param>
        /// <returns></returns>
        public static bool IsEmailAddress(string emailAdd)
        {
            return Regex.IsMatch(emailAdd, EmailPattern);
        }
        #endregion

        #region  判断是否是固定电话号码
        /// <summary>
        /// 匹配Phone的正则表达式
        /// </summary>
        public static string PhonePattern = @"^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$";
        
        /// <summary>
        /// 判断是否是固定电话号码
        /// </summary>
        /// <param name="phoneStr"></param>
        /// <returns></returns>
        public static bool IsPhone(string phoneStr)
        {
            return Regex.IsMatch(phoneStr, PhonePattern);
        }
        #endregion

        #region 判断是否是移动电话号码
        /// <summary>
        /// 匹配移动号码的正则表达式
        /// </summary>
        public static string MobilePattern = @"^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$";
        
        /// <summary>
        /// 判断字符串是否是移动电话号码
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public static bool IsMobile(string mobile)
        {
            return Regex.IsMatch(mobile ,MobilePattern );
        }
        #endregion

        #region 判断是否是网址
        /// <summary>
        /// 匹配网址的正则表达式
        /// </summary>
        public static string UrlPattern = @"http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?";

        /// <summary>
        /// 判断字符串是否是网址
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static bool IsUrl(string url)
        {
            return Regex.IsMatch(url, UrlPattern);
        }
        #endregion

        #region 判断是否是中文
        /// <summary>
        /// 匹配中文的正则表达式
        /// </summary>
        public static string ChinesePattern = @"^[\u0391-\uFFE5]+$";

        /// <summary>
        /// 判断字符串是否是中文
        /// </summary>
        /// <param name="chinese"></param>
        /// <returns></returns>
        public static bool IsChinese(string chinese)
        {
            return Regex.IsMatch(chinese, ChinesePattern);
        }
        #endregion

        #region 判断是否是英文
        /// <summary>
        /// 匹配英文的正则表达式
        /// </summary>
        public static string EnglishPattern = @"^[A-Za-z]+$";

        /// <summary>
        /// 判断字符串是否是英文
        /// </summary>
        /// <param name="english"></param>
        /// <returns></returns>
        public static bool IsEnglish(string english)
        {
            return Regex.IsMatch(english, EnglishPattern);
        }
        #endregion

        #region 判断是否是邮编
        /// <summary>
        /// 匹配邮编的正则表达式
        /// </summary>
        public static string ZipPattern = @"^[1-9]\d{5}$";

        /// <summary>
        /// 判断字符串是否是邮编
        /// </summary>
        /// <param name="zip"></param>
        /// <returns></returns>
        public static bool IsZip(string zip)
        {
            return Regex.IsMatch(zip, ZipPattern);
        }
        #endregion

        #region 判断是否是身份证号码
        /// <summary>
        /// 匹配身份证号码的正则表达式
        /// </summary>
        public static string IDCardPattern = @"^\d{15}(\d{2}[A-Za-z0-9])?$";

        /// <summary>
        /// 判断字符串是否是身份证号码
        /// </summary>
        /// <param name="idCard"></param>
        /// <returns></returns>
        public static bool IsIDCard(string idCard)
        {
            return Regex.IsMatch(idCard, IDCardPattern);
        }
        #endregion

        #region 判断是否是双精度浮点数
        /// <summary>
        /// 双精度浮点数的正则表达式
        /// </summary>
        public static string DoublePattern = @"^[-\+]?\d+(\.\d+)?$";

        /// <summary>
        /// 判断字符串是否是双精度浮点数
        /// </summary>
        /// <param name="doubleStr"></param>
        /// <returns></returns>
        public static bool IsDouble(string doubleStr)
        {
            return Regex.IsMatch(doubleStr, DoublePattern);
        }
        #endregion

        #region 判断是否是整数
        /// <summary>
        /// 匹配整数的正则表达式
        /// </summary>
        public static string IntegerPattern = @"^[-\+]?\d+$";

        /// <summary>
        /// 判断字符串是否是整数
        /// </summary>
        /// <param name="integer"></param>
        /// <returns></returns>
        public static bool IsInteger(string integer)
        {
            return Regex.IsMatch(integer, IntegerPattern);
        }
        #endregion

        #region 判断是否是数字
        /// <summary>
        /// 匹配数字的正则表达式
        /// </summary>
        public static string NumberPattern = @"^\d+$";

        /// <summary>
        /// 判断字符串是否是数字
        /// </summary>
        /// <param name="number"></param>
        /// <returns></returns>
        public static bool IsNumber(string number)
        {
            return Regex.IsMatch(number, NumberPattern);
        }
        #endregion

        #region 判断是否是QQ号码
        /// <summary>
        /// 匹配QQ号码的正则表达式
        /// </summary>
        public static string QQPattern = @"^[-\+]?\d+$";

        /// <summary>
        /// 判断字符串是否是QQ号码
        /// </summary>
        /// <param name="qq"></param>
        /// <returns></returns>
        public static bool IsQQ(string qq)
        {
            return Regex.IsMatch(qq, QQPattern);
        }
        #endregion

        #region 判断是否是时间格式字符串 01:01:01
        /// <summary>
        /// 匹配 时间格式字符串 01:01:01 的正则表达式
        /// </summary>
        public static string TimePattern = @"^[0-1][0-9]|2[0-3]:[0-5][0-9]:[0-5][0-9]$";

        /// <summary>
        /// 判断字符串是否是 时间格式字符串 01:01:01
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static bool IsTime(string time)
        {
            return Regex.IsMatch(time, TimePattern);
        }
        #endregion        
    }
}
